var app=angular.module('myApp', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
		when('/', {templateUrl: 'clientdetails_form.html', controller: ListCustCtrl}). 
		//when('/upd', {templateUrl: 'clientdetails_form.html', controller: ListCustCtrl}).
		otherwise({redirectTo: '/'});
}]);


function ListCustCtrl($scope,$http)
 {	
	$http.get('clientdetails_data.php').success(function(data1) 
	{		
		$scope.cdata = data1[0];	
		//alert(JSON.stringify(data1[0], null, 4));
	});
	
	$scope.upd = function(cd) 
	{		
		if(!cd.custname || !cd.addrline1 || !cd.city || !cd.addrline2 || !cd.addrline3|| !cd.phone1 || !cd.phone2 || !cd.emailgen || !cd.compemails || !cd.bank || !cd.ifsc || !cd.accountno || !cd.entries)
		{
			document.getElementById("msg").innerHTML='<div style="color:#FF0000;">Please fill all fields marked with *</div>';
			alert("Please fill all mandatory fields");
		}			
		else{
			var sql="clientdetails_update.php?&custname="+cd.custname+"&addrline1="+cd.addrline1+"&addrline2="+cd.addrline2+"&addrline3="+cd.addrline3+"&city="+cd.city+"&state="+cd.state+"&country="+cd.country+"&phone1="+cd.phone1+"&phone2="+cd.phone2+"&mobile1="+cd.mobile1+"&mobile2="+cd.mobile2+"&logo="+cd.logo+"&emailgen="+cd.emailgen+"&compemails="+cd.compemails+"&bank="+cd.bank+"&ifsc="+cd.ifsc+"&accountno="+cd.accountno+"&entries="+cd.entries;	
		//alert(sql);
		$http.post(sql).success(function(data)  
		{
			//window.location.href = 'clientdetails_form.php';		
			//window.location.href = sql;
			document.getElementById("msg").innerHTML="<div style='color:#0000A0;'> All changes are saved</div>";
			alert("Record updated successfully!");
		});
		}
	} //end fn upd 
 }//end fn listcustctrl
 
     app.directive('capitalize', function () {
        return {
            require: 'ngModel',
            link: function (scope, element, attrs, modelCtrl) {
                var capitalize = function (inputValue) {
                    if (angular.isUndefined(inputValue))
                        return;
 
                    var capitalized = inputValue.toUpperCase();
                    if (capitalized !== inputValue) {
                        modelCtrl.$setViewValue(capitalized);
                        modelCtrl.$render();
                    }
                    return capitalized;
                };
                modelCtrl.$parsers.push(capitalize);
                capitalize(scope[attrs.ngModel]);  // capitalize initial value
            }
        };
    });
    
        
        
 function AddCustCtrl($scope, $http, $location,$window) 
   {
      $scope.master = {};
      $scope.activePath = null;	  	 	        
    }


